/**
 * 
 */
  $(document).ready(function() {
	  var options = { 
		    	 url:"/salonmorandsmigi/UserServlet?action=register", 
		    	 success:function() { 
	    		 			$(".submit").append("<div class=\"success\">Registered successfully! move to login</div>");
	    		 			setTimeout("$(\".success\").remove();",2000);
	    		 			setTimeout("window.location.href =\"/salonmorandsmigi/index.jsp\";",3000);
	    	 				},
			     statusCode: {
			    	 			400: function() {
				    	 			$(".submit").append("<div class=\"fail\">FAIL! wrong admin code! try again!<\div>");
				    	 			setTimeout("$(\".fail\").remove();",2000);
			    	 			},
		    	 				405: function() {
		    	 					$(".submit").append("<div class=\"fail\">FAIL! username already exist in system<\div>");
				    	 			setTimeout("$(\".fail\").remove();",2000);
		    	 				},
		    	 				500: function() {
		    	 					$(".submit").append("<div class=\"fail\">FAIL! server error!<\div>");
				    	 			setTimeout("$(\".fail\").remove();",2000);
		    	 				}
							 }
		    	}; 
	  $("#newUser").validate({
			rules: {
				username: {
					required: true,
					minlength: 3,
					maxlength: 256
				},
				password: {
					required: true,
					minlength: 4,
					maxlength: 19
				},
				cpassword: {
					required: true,
					minlength: 4,
					maxlength: 19,
					equalTo: "#password"
				},
				name: {
					required: true,
					maxlength: 256
				},
				phone:{
					required: true,
					number: true,
					maxlength: 15
				}
			},
			messages: {
				username: {
					required: "Please enter the username",
					minlength: "username can't be shorter then 3 letters",
					maxlength: "username can't be longer then 256 letters" 
				},
				password: {
					required: "please enter a password",
					minlength: "a password can't be shorter then 4 letters",
					maxlength: "a password can't be longer then 19 letters"
				},
				cpassword: {
					required: "please enter a password",
					minlength: "a password can't be shorter then 4 letters",
					maxlength: "a password can't be longer then 19 letters",
					equalTo:   "passwords doesnt match"
				},
				name: {
					required: "please enter a name",
					maxlength: "a password can't be longer then 256 letters"
				},
				phone:{
					required: "please enter a phone number",
					number: "phone number must me a number",
					maxlength: "phone number must have less then 15 digits"
				}
			},
			submitHandler: function(form) {
				
			   	$(form).ajaxSubmit(options);
			}
		});
  });
    
